package com.gec.controller;
import com.gec.pojo.Users;
import com.gec.service.userService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;

/**
 * @author 12691
 * @version 1.0
 * @description: TODO
 * @date 2024/9/9 17:10
 */
@Controller
//@ComponentScan("com.gec.service")
public class userController {
    @Autowired
    private userService userService;

    @RequestMapping(value = "/getUsers")
    public String users(Model model) {


//        PageHelper.startPage(1,3);
        List<Users> users = userService.getUsers();
        model.addAttribute("userList", users);
        return "userlist";

    }

    //添加用户
    @PostMapping("/addUser")
    public String addUser(Users users) {
        Integer integer = userService.addUser(users);
        return "redirect:/getUsers";
    }

    @GetMapping("/input")
    public String inputPage() {
        return "addUser";
    }


    @GetMapping("/delete")
    public String deleteUser(Integer id) {
        userService.deleteUser(id);
        return "redirect:/getUsers";
    }

    @GetMapping("queryById")
    public String queryById(Integer id,Model model) {
        Users users = userService.queryByid(id);
        model.addAttribute("user",users);
        return "update";

    }
    @PostMapping("update")
    public String update(Users users){
        userService.update(users);
        return  "redirect:/getUsers";
    }
}
